<template>
  <view class="u-page">
    <view class="cell-page">
      <view class="u-page__item">
        <text class="u-page__item__title">您已提交成功</text>
        <u-cell-group>
			<u-cell size="large" >
				<view slot="title"  class="u-slot-title">
					<text class="big-tip">{{state | formatText}}</text>
				</view>
			</u-cell>
		</u-cell-group>
      </view>
    </view>
	<!-- <view v-if="state == '4'">
		<view class="u-flex mt-2" >
		  <text class="">消息</text>
		</view>
		<text class="font-tip text-indent" >{{reason}}</text>
	</view> -->
    <view class="cell-page" v-if="state == '4'">
      <view class="u-page__item">
        <text class="u-page__item__title">消息</text>
        <u-cell-group>
			<u-cell >
				<view slot="title"  class="u-slot-title">
					<text class="big-tip" >{{reason}}</text>
				</view>
			</u-cell>
		</u-cell-group>
      </view>
    </view>
	<view class="cell-page">
	  <view class="u-page__item">
	    <text class="u-page__item__title">提示</text>
	    <u-cell-group>
			<u-cell size="large" >
				<view slot="title"  class="u-slot-title">
					<text class="big-tip">{{state | formatMessage}}</text>
				</view>
			</u-cell>
		</u-cell-group>
	  </view>
	</view>
	<!-- <view class="u-flex mt-2">
	  <text class="">提示</text>
	</view>
	<text class="font-tip text-indent">{{state | formatMessage}}</text> -->
    <!-- <view class="cell-page" v-if="state == '2'">
      <view class="u-page__item">
        <text class="u-page__item__title">提示</text>
        <u-cell-group><u-cell title="待材料核验通过后,我们将以短信的形式通知您进行下一步操作,请耐心等待。"></u-cell></u-cell-group>
      </view>
    </view>
    <view class="cell-page" v-if="state == '3'">
      <view class="u-page__item">
        <text class="u-page__item__title">提示</text>
        <u-cell-group><u-cell title="材料审核已通过，请耐心等待我们以短信形式发送的,下一步操作通知。"></u-cell></u-cell-group>
      </view>
    </view>
    <view class="cell-page" v-if="state == '4'">
      <view class="u-page__item">
        <text class="u-page__item__title">提示</text>
        <u-cell-group><u-cell title="材料审核未通过，请参照未通过'消息',仔细核对后重新上报。"></u-cell></u-cell-group>
      </view>
    </view> -->
    <u-row class="w-100 mt-4" justify="center" v-if="state == '4'">
      <u-col span="5" justify="center">
        <u-button type="primary" shape="circle" @click="reset"><view>重 填</view></u-button>
      </u-col>
    </u-row>
  </view>
</template>

<script>
import { checkState, restart } from '@/common/api/mcRegister.js';
import { pathToBase64 } from 'image-tools';

export default {
  filters: {
    formatText(text) {
      switch (text) {
        case 1:
          return '未申请';
        case 2:
          return '审核中';
        case 3:
          return '已通过';
        case 4:
          return '未通过';
        case 5:
          return '已领取';
      }
    },
	formatMessage(text) {
	  switch (text) {
	    case 1:
	      return '您未提交资料，请重新进入系统！';
	    case 2:
	      return '待材料核验通过后,我们将以短信的形式通知您进行下一步操作,请耐心等待。';
	    case 3:
	      return '材料审核已通过，请耐心等待我们以短信形式发送的,下一步操作通知。';
	    case 4:
	      return '材料审核未通过，请参照未通过"消息",仔细核对后重新上报。';
	    case 5:
	      return '已领取';
	  }
	},
  },
  data() {
    return {
      state: 1,
      reason: '',
      idCard: '',
	  name:'',
      currentStep: 'result',
      form: {
        caseList: [],
      },
    };
  },
  onLoad(options) {
    const { cid = '' } = options;
    if (cid === '') {
      this.toMcIndex();
    }

    this.form.caseList = cid.split(',').map(id => {
      return { cid: id };
    });
    uni.showLoading({
      title: '数据加载中',
    });
    checkState(this.form).then(res => {
      const { data = {} } = res;
      const { state, reason, idCardNo,name } = data;
      this.state = state;
      this.reason = reason;
      this.idCard = idCardNo;
	  this.name = name;
      uni.hideLoading();
    });
  },
  methods: {
    reset() {
      restart(this.form).then(({data={}})=>{
		  // 图片路径转base64
		  let faceImageBase = ''
		  let faceImageUrl = data.oneself ? data.idCardFaceUrl : data.idCard1FaceUrl
		  uni.getImageInfo({
		  		src: faceImageUrl,
		  		success: res => {
				  pathToBase64(res.path).then(base64 => {
					  console.log('base64:' + base64)
						faceImageBase = base64.replace(/^data:image\/\w+;base64,/, '');
						this.reSaveInfo(data, faceImageBase);
						this.toMcRstart(this.name);
				  }).catch(error => {
					console.error(error)
				  })
		  		},
		  		fail: err => {
		  			console.log(err, 'err')
		  		}
		  })
        // this.reSaveInfo(data);
        // this.toSrRstart();
      })
    },
    reSaveInfo(data, faceBase64) {
      const {
        searchValue,
        createBy,
        createTime,
        updateBy,
        updateTime,
        remark,
        params,
        id,
        personId,
        idCardPositiveUrl,
        idCardFaceUrl,
        idCardBackUrl,
        bankCardPositiveUrl,
        bankCardNo,
        bankCardBackUrl,
        name1,
        idCard1No,
        name2,
        idCard2No,
        contactNumber,
        idCard1PositiveUrl,
        idCard1FaceUrl,
        idCard1BackUrl,
        bankCard1PositiveUrl,
        bankCard1No,
        bankCard1BackUrl,
        deathCertificateUrl,
        fundRaisingDate,
        relation,
        adress,
        adress1,
        fillingDate,
        oneself,
        videoUrl,
        videoFaceUrl,
        sign,
        step,
        area,
        billNo1,
        oldBankCardNo1,
        registeredResidence,
        bills,
        authenticAct,
        cid,
        name,
        idCardNo,
        actualInvestmentAmount,
        actualAmountOfPrincipalAndInterestReturned,
        actualLossAmount,
        actualAmountOfLossToBeReturned,
        state,
        reason,
        signBase64,
        type,
        billNo,
        oldBankCardNo,
        collectFlag,
        caseList,
		nameOnCard,
		brankArea,
		bankName,
		mailingAddress,
		losedDate,
      } = data;
	  
      const info = {
        idCard: idCardNo,
        index: { idCardNo, name },
        step: 'index',
        step0_5: { billNo: billNo ? billNo.split(',') : [], oldBankCardNo },
        step1: {
          actualAmountOfLossToBeReturned,
          actualAmountOfPrincipalAndInterestReturned,
          actualInvestmentAmount,
          actualLossAmount,
          idCardBackUrl,
          idCardFaceUrl,
          idCardNo,
          idCardPositiveUrl,
          name,
          oneself,
          reason,
          state,
		  losedDate,
		  idCardFaceBase64: oneself ? faceBase64 : null
        },
        step1_5: {
          authenticAct,
          deathCertificateUrl,
          idCard1BackUrl,
          idCard1FaceUrl,
          idCard1No,
          idCard1PositiveUrl,
          idCardNo,
          name1,
          registeredResidence,
          relation,
		  idCard1FaceBase64: oneself ? null : faceBase64
        },
        step2: {
          bankCard1No,
          bankCard1PositiveUrl,
          bankCardNo,
          bankCardPositiveUrl,
          bills,
          contactNumber,
          idCardNo,
		  nameOnCard,
		  brankArea,
		  bankName,
		  mailingAddress
        },
        step3: {
          actualAmountOfLossToBeReturned,
          actualAmountOfPrincipalAndInterestReturned,
          actualInvestmentAmount,
          actualLossAmount,
          authenticAct,
          bankCard1BackUrl,
          bankCard1No,
          bankCard1PositiveUrl,
          bankCardBackUrl,
          bankCardNo,
          bankCardPositiveUrl,
          bills,
          contactNumber,
          deathCertificateUrl,
          idCard1BackUrl,
          idCard1FaceUrl,
          idCard1No,
          idCard1PositiveUrl,
          idCardBackUrl,
          idCardFaceUrl,
          idCardNo,
          idCardPositiveUrl,
          name,
          name1,
          oneself,
          reason,
          registeredResidence,
          relation,
          sign,
          state,
          step,
          videoFaceUrl,
          videoUrl
        },
      };
      this.$setMcInfo(idCardNo,info)
    },
  },
};
</script>

<style scoped lang="scss"></style>
